package org.huangrui.design.pattern.singleton;

/*
 * 饿汉式
 * 在类初始化时直接创建实例对象，不管你是否需要这个对象都会创建
 * 1）构造器私有化
 * 2)自行创建，并且用静态变量保存
 * 3）向外提供这个实例
 * 4）强调这是一个单例，我们可以用final修改
 * @author hr
 * @create 2025-09-09 14:11
 */
public class Singleton1 {
	private static final Singleton1 INSTANCE = new Singleton1();
	private Singleton1(){
	}
	public static Singleton1 getInstance(){
		return INSTANCE;
	}
	public static void main(String[] args) {
		Singleton1 instance = Singleton1.INSTANCE;
		System.out.println(instance);
		Singleton1 instance3 = Singleton1.INSTANCE;
		System.out.println(instance3);
		System.out.println(instance == instance3);

		Singleton2 singleton2 = Singleton2.INSTANCE;
		System.out.println(singleton2);
	}
}
